package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TTransactionDetail;
import com.ruoyi.system.service.ITTransactionDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收入、支出、转移的明细列Controller
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@RestController
@RequestMapping("/system/transactionDetail")
public class TTransactionDetailController extends BaseController
{
    @Autowired
    private ITTransactionDetailService tTransactionDetailService;

    /**
     * 查询收入、支出、转移的明细列列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TTransactionDetail tTransactionDetail)
    {
       if(tTransactionDetail.getTransactionDate1()!=null){
           tTransactionDetail.setTD1(tTransactionDetail.getTransactionDate1()[0]);
           tTransactionDetail.setTD2(tTransactionDetail.getTransactionDate1()[1]);
       }
       if(tTransactionDetail.getProofDate1()!=null){
           tTransactionDetail.setPD1(tTransactionDetail.getProofDate1()[0]);
           tTransactionDetail.setPD2(tTransactionDetail.getProofDate1()[1]);
       }
       if(tTransactionDetail.getPredictDate1()!=null){
           tTransactionDetail.setpD1(tTransactionDetail.getPredictDate1()[0]);
           tTransactionDetail.setpD2(tTransactionDetail.getPredictDate1()[1]);
       }
        startPage();
        List<TTransactionDetail> list = tTransactionDetailService.selectTTransactionDetailList(tTransactionDetail);
        return getDataTable(list);
    }

    /**
     * 导出收入、支出、转移的明细列列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTransactionDetail tTransactionDetail)
    {
        List<TTransactionDetail> list = tTransactionDetailService.selectTTransactionDetailList(tTransactionDetail);
        ExcelUtil<TTransactionDetail> util = new ExcelUtil<TTransactionDetail>(TTransactionDetail.class);
        util.exportExcel(response, list, "收入、支出、转移的明细列数据");
    }

    /**
     * 获取收入、支出、转移的明细列详细信息
     */
    @GetMapping(value = "/{tid}")
    public AjaxResult getInfo(@PathVariable("tid") Long tid)
    {
        return AjaxResult.success(tTransactionDetailService.selectTTransactionDetailByTid(tid));
    }

    /**
     * 新增收入、支出、转移的明细列
     */
    @PostMapping
    public AjaxResult add(@RequestBody TTransactionDetail tTransactionDetail)
    {
        return toAjax(tTransactionDetailService.insertTTransactionDetail(tTransactionDetail));
    }

    /**
     * 修改收入、支出、转移的明细列
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TTransactionDetail tTransactionDetail)
    {
        return toAjax(tTransactionDetailService.updateTTransactionDetail(tTransactionDetail));
    }

    /**
     * 删除收入、支出、转移的明细列
     */
	@DeleteMapping("/{tids}")
    public AjaxResult remove(@PathVariable Long[] tids)
    {
        return toAjax(tTransactionDetailService.deleteTTransactionDetailByTids(tids));
    }
}
